<template>
  <div>
    <PageHeader hidden-breadcrumb>
        <template #title><div class="demo-title">用户管理</div></template>
        <template #content>
          <div class="demo-content">页面数据为 Mock 示例数据，非真实数据。</div>
        </template>
    </PageHeader>
    <Card style="margin:20px;">
      <Button type="primary" icon="md-add" ghost>新增用户</Button>
      <div class="ivu-inline-block ivu-fr">
        <Dropdown trigger="click">
          <Tooltip content="密度" placement="top">
            <Icon type="md-list" size="16"></Icon>
          </Tooltip>
          <template #list>
              <DropdownMenu>
                  <DropdownItem>默认</DropdownItem>
                  <DropdownItem>宽松</DropdownItem>
                  <DropdownItem>紧凑</DropdownItem>
              </DropdownMenu>
          </template>
        </Dropdown>
        <Tooltip content="全屏" placement="top" style="margin-left:10px;">
          <Icon type="md-expand" size="16"></Icon>
        </Tooltip>
        <Tooltip content="刷新" placement="top" style="margin-left:10px;">
          <Icon type="ios-refresh" size="18"/>
        </Tooltip>
        <Dropdown trigger="click" style="margin-left:10px;">
          <Tooltip content="列设置" placement="top">
            <Icon type="md-options" size="16"></Icon>
          </Tooltip>
          <template #list>
              <DropdownMenu>
                  <DropdownItem>Name</DropdownItem>
                  <DropdownItem>Age</DropdownItem>
                  <DropdownItem>Address</DropdownItem>
              </DropdownMenu>
          </template>
        </Dropdown>
      </div>
      <Table :columns="columns" :data="data" style="margin-top:16px;">
        <template #name="{ row }">
            <strong>{{ row.name }}</strong>
        </template>
        <template #action="{ row, index }">
            <Button type="text" size="small" style="margin-right: 5px" @click="show(index)"><a>编辑</a></Button>
            <Button type="text" size="small" @click="remove(index)"><a>删除</a></Button>
        </template>
      </Table>
      <div class="ivu-mt ivu-text-center">
        <Page :total="100" show-sizer />
      </div>
    </Card>
  </div>
</template>

<script>
    export default {
        data () {
            return {
                columns: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: 'Name',
                        slot: 'name'
                    },
                    {
                        title: 'Age',
                        key: 'age'
                    },
                    {
                        title: 'Address',
                        key: 'address'
                    },
                    {
                        title: 'Action',
                        slot: 'action',
                        width: 150,
                        align: 'center'
                    }
                ],
                data: [
                    {
                        name: 'John Brown',
                        age: 18,
                        address: 'New York No. 1 Lake Park'
                    },
                    {
                        name: 'Jim Green',
                        age: 24,
                        address: 'London No. 1 Lake Park'
                    },
                    {
                        name: 'Joe Black',
                        age: 30,
                        address: 'Sydney No. 1 Lake Park'
                    },
                    {
                        name: 'Jon Snow',
                        age: 26,
                        address: 'Ottawa No. 2 Lake Park'
                    },
                    {
                        name: 'Jim Green',
                        age: 24,
                        address: 'London No. 1 Lake Park'
                    },
                    {
                        name: 'Joe Black',
                        age: 30,
                        address: 'Sydney No. 1 Lake Park'
                    },
                    {
                        name: 'Jon Snow',
                        age: 26,
                        address: 'Ottawa No. 2 Lake Park'
                    }
                ]
            }
        },
        methods: {
            show (index) {
                this.$Modal.info({
                    title: 'User Info',
                    content: `Name：${this.data[index].name}<br>Age：${this.data[index].age}<br>Address：${this.data[index].address}`
                })
            },
            remove (index) {
                this.data.splice(index, 1);
            }
        }
    }
</script>
